home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)in_create.c V1.27 8/15/95";
- #endif
- /*
- | file name in_create.c
- |===================================================================
- |
- | This programs show how to create input objects
- | programmatically.
- |
- | This program creates a Combiner that contains several
- | embedded input objects. The embedded input objects consist
- | of a slider, a text entry field, an object toggle, a color
- | palette, a text menu, and an checklist.
- |
- |===================================================================
- */
- #include <windows.h>
- /*
- * DV-Tools header files
- */
- #include "std.h" /* <stdio.h> etc., scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
- #include "VOfundecl.h" /* VO routines (objects) */
- #include "VUerfundecl.h" /* VUer routines (event handling routines) */
- #include "VPfundecl.h" /* VP routines (put info for dgp & vdp) */
-
- /* Constants */
- #define DVPATH (char *)NULL
- #define DISPFORMS_STB (char *)NULL
- #define DVDEVICE (char *)NULL
- #define DVCOLORTABLE (char *)NULL
- #define SCREEN_VIEWPORT (RECTANGLE *)NULL
- #define TEXTBUFSIZE 80
-
- /* Whole world rectangle, (-16384, -16384) to (16383, 16383)*/
- LOCAL RECTANGLE whole_world = {XMIN, YMIN, XMAX, YMAX};
-
- /* Define buffers for input objects */
- char TextValue[TEXTBUFSIZE] = {'H', 'i', 0,};
- float SliderValue = 1.0, /* slider buffer */
- ToggleValue, /* object toggle buffer */
- PaletteValue, /* color palette buffer */
- MenuValue, /* text menu buffer */
- ChecklistValues[8]; /* checklist buffer */
-
- /* Define list of pickable items for text menu */
- char *Menu[]=
- {
- "DataViews Corp.", "DataViews", "DV-Draw", "DV-Tools", "DV-Play"
- };
-
- /* Define interaction handlers */
- GLOBALREF INHANDLER VNcombiner, VNslider, VNtext, VNtoggle, VNpalette,
- VNmenu, VNchecklist;
-
- /* Define list of layout view file names */
- char *LayoutNames[]=
- {
- "DefSlider.lay",
- "DefText.lay",
- "DefObjTogg.lay",
- "DefPalette.lay",
- "Menu_v5.lay",
- "DefObjCh.lay"
- };
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- INT argc = 0;
- CHAR **argv;
- /*
- * program arguments
- * argv[1] - display device (default is DVDEVICE)
- */
-
- /* Define & initialize device name and view filename */
- char *device_name = DVDEVICE; /* default device name */
-
- /* Define display variables */
- OBJECT screen; /* display device, the window */
- DRAWPORT drawport; /* how & where to display picture, picture frame */
- VIEW view; /* picture representation of the view file */
-
- /* Control loop variables */
- OBJECT location; /* the event representation */
- int event_status; /* how the event handler has used the location
- event */
-
- /* Other variables */
- int Quit = NO; /* flag to quit program */
- int i; /* counter */
-
- /* Input object related variables */
- ATTRIBUTES Attributes; /* attribute structure */
- VIEW TemplateView; /* template view */
- OBJECT TemplateDrawing; /* drawing object of template view */
- OBJECT LLcorner, /* lower left pt of input obj */
- URcorner, /* upper right pt of input obj */
- CombinerInput, /* combiner input obj */
- CombinerTechnique, /* combiner input technique obj */
- InputObjects[6], /* embedded input objects */
- InputTechs[6]; /* embedded input objs technique objs */
- INHANDLER InputHandlers[6]; /* list of interaction handlers */
- VARDESC Vdps[13]; /* variable descriptors for input objs */
-
- /*--------------------
- * Initialization
- *
- * TInit: perform the initialization of DV-Tools
- * TInit reads your configuration file and any
- * environment variables or logical names set.
- */
- make_argv(&argc,&argv,GetCommandLine());
- TInit (DVPATH, DISPFORMS_STB);
-
- /*
- * TscOpenSet: open a device as a screen object using
- * specified attributes
- * TscErase: erase the entire screen in the default
- * background color
- *
- * Set exposure block to YES to insure the window
- * is ready for drawing when TdpDraw is called.
- */
- if (argc > 1)
- device_name = argv[1];
- screen = TscOpenSet (device_name, DVCOLORTABLE,
- V_X_EXPOSURE_BLOCK, YES,
- V_ACTIVE_CURSOR, V_END_OF_LIST);
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- S_EXIT (EXIT_ERR);
- }
-
- /*
- * VOscWinEventMask: sets the screen's window event mask
- */
- VOscWinEventMask ((ULONG) V_KEYPRESS | V_KEYRELEASE |
- V_BUTTONPRESS | V_BUTTONRELEASE |
- V_MOTIONNOTIFY | V_EXPOSE | V_RESIZE,
- (ULONG) 0);
-
- /*
- * TviCreate: create a view which will be empty.
- * TdpCreateStretch: Create a DV-tools window, a drawport
- * "drawport" is attached to the screen object, "screen"
- * "view" is the view to be displayed on the screen
- * "SCREEN_VIEWPORT" specifies the area of the screen
- * to use to display the drawport
- * "whole_world" specifies the portion of the view to be
- * displayed, here the whole view
- * The whole view will be stretched to fit in the drawport
- */
- view = TviCreate ();
- drawport = TdpCreateStretch (screen, view,
- SCREEN_VIEWPORT, &whole_world);
-
- /*
- * VUerPutKeys: Sets the key-action bindings
- * define the left mouse button as the select
- * keys while the right mouse button will
- * represent the cancel key.
- */
- VUerPutKeys (SELECT_KEYS, "\001");
- VUerPutKeys (CANCEL_KEYS, "\003");
-
- /*
- * VOuAtInit: Sets all attribute fields to EMPTY_FIELD.
- * VOcoCreate: Create a color or RGB object
- * VOptCreate: Create a point object
- *
- * Initialize the attributes structure and fill the fields
- * representing foreground and background color. Also,
- * create the control points to be used by the combiner
- * input object and its embedded input objects
- */
- VOuAtInit (&Attributes);
- Attributes.foreground_color = VOcoCreate (COLOR_NAME, "white");
- Attributes.background_color = VOcoCreate (COLOR_NAME, "black");
- LLcorner = VOptCreate (WORLD_COORDINATES, -14000, -14000, (OBJECT) NULL);
- URcorner = VOptCreate (WORLD_COORDINATES, 14000, 14000, (OBJECT) NULL);
-
- /*
- * VOinCreate: Create an input object
- *
- * Create the embedded input objects (6).
- */
- for (i = 0; i <= 5; i++)
- InputObjects[i] = VOinCreate (LLcorner, URcorner, &Attributes);
-
- /*
- * VPvdcreate: Create a variable descriptor
- * VPvd_drange: Sets the range in doubles.
- * VPvddim: Specifies the dimensions of a variable
- *
- * Create the variable descriptors for each of the input objects.
- * The variable descriptors will be bound to program variables.
- */
- Vdps[0] = VPvdcreate ((ADDRESS) & SliderValue, V_F_TYPE);
- VPvd_drange (Vdps[0], 1.0, 2.0);
- Vdps[1] = VPvdcreate ((ADDRESS) TextValue, V_T_TYPE);
- VPvddim (Vdps[1], 1, 1, TEXTBUFSIZE);
- Vdps[2] = VPvdcreate ((ADDRESS) & ToggleValue, V_F_TYPE);
- Vdps[3] = VPvdcreate ((ADDRESS) & PaletteValue, V_F_TYPE);
- Vdps[4] = VPvdcreate ((ADDRESS) & MenuValue, V_F_TYPE);
-
- /*
- * VOinPutVarList: Sets the variable descriptor list
- *
- * Set the vdp list for each of the input objects.
- */
- for (i = 0; i <= 4; i++)
- VOinPutVarList (InputObjects[i], &Vdps[i], 1);
-
- /*
- * VPvdcreate: Create a variable descriptor
- * VOinPutVarList: Sets the variable descriptor list
- *
- * Create a variable descriptors for each of the elements
- * in the checklist. The variable descriptor will point to
- * an array element whose value with be 0 or 1.
- */
- for (i = 0; i <= 7; i++)
- Vdps[i + 5] = VPvdcreate ((ADDRESS) & ChecklistValues[i], V_F_TYPE);
- VOinPutVarList (InputObjects[5], &Vdps[5], 8);
-
- /*
- * VOitCreate: Create an input technique object
- * VOinTechnique: Sets the input technique to be used for this
- * input object.
- *
- * Load in the layout views which will define the appearance of
- * the input object. The drawing object of the view is obtained
- * and attached to the input technique. The input technique
- * defines the type of input object based on the interaction
- * handler and the appearance is defined by the layout file.
- */
- InputHandlers[0] = VNslider;
- InputHandlers[1] = VNtext;
- InputHandlers[2] = VNtoggle;
- InputHandlers[3] = VNpalette;
- InputHandlers[4] = VNmenu;
- InputHandlers[5] = VNchecklist;
- for (i = 0; i <= 5; i++)
- {
- TemplateView = TviLoad (LayoutNames[i]);
- TemplateDrawing = TviGetDrawing (TemplateView);
- InputTechs[i] = VOitCreate (InputHandlers[i], TemplateDrawing);
- VOinTechnique (InputObjects[i], InputTechs[i]);
- TviDestroy (TemplateView);
- }
-
- /*
- * VOitPutList: Sets the list of pickable items
- *
- * The fourth input technique object represents the input
- * technique for the text menu input object. The list of
- * selectable items is set using this routine.
- */
- VOitPutList (InputTechs[4], TEXT_LIST, (ADDRESS) Menu, 5);
-
- /*
- * Create the combiner input object and its technique object.
- * Attach the embedded input objects to the technique
- * and attach the technique to the combiner input object.
- */
- CombinerInput = VOinCreate (LLcorner, URcorner, &Attributes);
- TemplateView = TviLoad ("Combiner.lay");
- CombinerTechnique = VOitCreate (VNcombiner,
- TviGetDrawing (TemplateView));
- TviDestroy (TemplateView);
- VOitPutList (CombinerTechnique, OBJECT_LIST, (ADDRESS) InputObjects, 6);
- VOinPutVarList (CombinerInput, Vdps, 13);
- VOinTechnique (CombinerInput, CombinerTechnique);
-
- /*
- * VOdrObAdd: Adds an object to the drawing
- *
- * Add the combiner input object to the view's drawing.
- * The object will be drawn, updated and redrawn whenever
- * these actions are performed on the drawport containing
- * this view.
- */
- VOdrObAdd (TviGetDrawing (view), CombinerInput);
-
- /*
- * TscErase: erase the entire screen in the default
- * background color
- * TdpDraw: Draw the contents of a drawport
- *
- * Erase the screen and draw the drawport.
- */
- TscErase (screen);
- TdpDraw (drawport);
-
- /*--------------------
- * Control loop
- *
- * Poll the event queue for window events specified by the
- * window mask. Handle each of the events as they happen.
- * Events occurring within input objects will be handled
- * through the event request handler VUerHandleLocEvent.
- * Stop when the user selects "q|Q" or the right mouse button.
- */
- FOREVER
- {
- /*
- * VOloWinEventPoll: Poll for the next window event.
- *
- * VUerHandleLocEvent: Service the event. This routine will check
- * if the event is used by any input objects
- * that may be in the view.
- */
- location = VOloWinEventPoll (V_WAIT);
- event_status = VUerHandleLocEvent (location);
-
- /*
- * If the return value of VUerHandleLocEvent is INPUT_UNUSED
- * then check for keypress or buttonpress events which
- * represent one of the exit keys.
- */
- if (event_status == INPUT_UNUSED)
- {
- /*
- * VOloType: returns the type of event. These types
- * match event types specified in VOscWinEventMask.
- */
- switch (VOloType (location))
- {
- case V_EXPOSE:
- /*
- * VOloRegion: Returns a rectangle representing the
- * exposed region on the screen.
- * TscRedraw: After erasing, redraws all the drawports
- * in the screen.
- * A portion of the window has been exposed and needs
- * to be redrawn.
- */
- TscRedraw (screen, VOloRegion (location));
- break;
-
- case V_RESIZE:
- /*
- * TscReset: Resets all screen drawports after
- * window resizing
- * The window size has been changed.
- */
- TscReset (screen);
- break;
-
- case V_KEYPRESS:
- /*
- * Check key selected.
- * VOloKeySym: Returns the key symbol value of the
- * location object
- *
- * If the key symbol represents the characters 'q'
- * or 'Q' then quit the program.
- */
- switch (VOloKeySym (location))
- {
- case 'q':
- case 'Q':
- Quit = YES;
- break;
- }
-
- case V_BUTTONPRESS:
- /*
- * Check button selected.
- * VOloButton: Returns the button that was pressed
- *
- * The right mouse button exits the program.
- */
- switch (VOloButton (location))
- {
- case 3:
- Quit = YES;
- break;
-
- default:
- break;
- }
- break;
-
- case V_MOTIONNOTIFY:
- case V_KEYRELEASE:
- case V_BUTTONRELEASE:
- default:
- break;
- }
- }
-
- /* exit the program */
- if (Quit == YES)
- break;
- }
-
- /*--------------------
- * Termination
- *
- * TscErase: Erase the screen object
- * TdpDestroy: Destroy the drawport,
- * TviDestroy: Destroy the view, freeing the allocated memory
- * TscClose: Closes the screen object
- * TTerminate: Perform the clean-up for DV-Tools
- */
- TscErase (screen);
- TdpDestroy (drawport);
- TviDestroy (view);
- TscClose (screen);
- TTerminate ();
- return (EXIT_OK);
- }
-